package com.shop2cn.iapi.grouponmgr.testcase;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.shop2cn.iapi.activitymgt.parameter.AddactivityBean;
import com.shop2cn.iapi.grouponmgr.parameter.GrouponCatalogDto;
import com.shop2cn.iapi.grouponmgr.parameter.SaveGrouponReq;
import com.shop2cn.iapi.grouponmgr.service.SaveGrouponCall;
import com.shop2cn.iapi.sellerpromotion.parameter.CreatePromotionBean;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.DetailsCatalogDto;
import com.shop2cn.iapi.agentproducts.parameter.ImportAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsDto;
import com.ymatou.mq.admin.parameter.MessageListBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.AgentProductCallService;
import com.ymttest.business.service.MqQueryCallService;
import com.ymttest.business.service.Shop2cnGrouponCallService;
import com.ymttest.business.service.Shop2cnSellerPromotionCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.GrouponCatalogs;
import com.ymttest.database.model.GrouponProducts;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.utils.AgentUsers;
import com.ymttest.utils.YMTDateUtil;
/**
*创建编辑拼团
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SaveGroupon{
	private static SaveGrouponReq savegrouponBean;
	private static SaveGrouponCall savegrouponCall;
	YmtProductsIWapper YmtProductsIWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("创建编辑拼团");
	}

	@Before
	public void caseUp() {
		savegrouponBean=new SaveGrouponReq();
		savegrouponCall=new SaveGrouponCall();
		YmtProductsIWapper=new YmtProductsIWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(savegrouponCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	//vip渠道
		private static int vipRootUserId = AgentUsers.vipRootUserId;
		private static String vipRootUserName = "NickautoTest";
		private static int csId = AgentUsers.csId;
		private static String csName = "NickautoTest";
		//vip渠道->代理
		private static int vipAgentUserId1 = AgentUsers.vipAgentUserId1;
		private static String vipAgentUserName1 = "dgsq408897016";
		private static int csId1 = AgentUsers.csId1;
	/**
	 * 验证砍价团总线
	 * @param getGrouponProductId
	 * @param pid
	 * @param qcode
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws InterruptedException 
	 */
	private void verifyGroupMq(Integer getGrouponProductId, String pid,String qcode) throws ClientProtocolException, IOException, InterruptedException {
		Thread.sleep(1000);
		MessageListBean MessageListBean = MqQueryCallService.initGroupon(pid, qcode);
		List<Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
		Logger.debug(joa);
		// {"EndTime":"4000-01-31
		// 23:59:00","GroupExpiredHours":6,"GroupMemberCount":2,"GrouponProductId":33,"ProductId":"p1158472"}
		Logger.comment("验证砍价团总线消息");
		Logger.verifyEquals(savegrouponBean.getGrouponMaxHour(), joa.get(0).get("GroupExpiredHours"), "验证GroupExpiredHours");
		List<GrouponProducts> gp = YmtProductsIWapper.selectGrouponProducts(pid, null, 0);

		Logger.verifyEquals(gp.get(0).getGrouponMemberCount(), joa.get(0).get("GroupMemberCount"), "验证GroupMemberCount");
		Logger.verifyEquals(getGrouponProductId, joa.get(0).get("GrouponProductId"), "验证GrouponProductId");
		Logger.verifyNotNull(joa.get(0).get("EndTime"), "验证EndTime");
		Logger.verifyNotNull(joa.get(0).get("BeginTime"), "验证EndTime");
		Logger.verifyEquals(pid, joa.get(0).get("ProductId"), "验证ProductId");
	}
	/**
	 * 验证同步指令
	 * @param getGrouponProductId
	 * @param pid
	 * @param code
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 * @throws InterruptedException 
	 */
	private void verifyMongoCurMq(Integer getGrouponProductId, String pid, String code) throws ClientProtocolException, IOException, InterruptedException {
		Thread.sleep(1000);
		List<GrouponProducts> gp = YmtProductsIWapper.selectGrouponProducts(savegrouponBean.getProductId(), null, 0);
		String version = gp.get(0).getVersion().toString();
		MessageListBean MessageListBean2 = MqQueryCallService.initPMongoCrud(pid);
		List<Map> joa2 = MqQueryCallService.GetMqMessage(MessageListBean2);
		Logger.debug(joa2);
		Logger.verifyEquals(code, joa2.get(0).get("ActionType"), "验证ActionType");
		Logger.verifyEquals(getGrouponProductId, joa2.get(0).get("ActivityId"), "验证ActivityId");
		Logger.verifyEquals(version, joa2.get(0).get("ExtParam"), "验证ExtParam-version");
		// [{"ActionType":"CreateGroupon","ActivityId":33,"AppId":"productmanager.iapi.ymatou.com","ExtParam":"2013","ProductId":"p1158472","SellerId":0,"TransactionId":2611926},
		// {"ActionType":"CreateProduct","ActivityId":0,"AppId":"productmanager.iapi.ymatou.com","ProductId":"p1158472","SellerId":0,"TransactionId":2611925}]
	}
	/**
	 * @param savegrouponBean2
	 * @return getGrouponProductId
	 */
	private Integer verifyDB(SaveGrouponReq savegrouponBean2,boolean isModify) throws InterruptedException {
		List<GrouponProducts> gp = YmtProductsIWapper.selectGrouponProducts(savegrouponBean2.getProductId(), null, 0);
		if(gp.size()==0){
		Logger.verifyEquals(1, gp.size(), "验证当前有效拼团数量");
		if (savegrouponBean2.getGrouponMemberCount()!=0&&savegrouponBean2.getGrouponMemberCount()>=2){
			Logger.verifyEquals(savegrouponBean2.getGrouponMemberCount(), gp.get(0).getGrouponMemberCount(), "验证当前拼团人数");
		}else{
			Logger.verifyEquals(2, gp.get(0).getGrouponMemberCount(), "验证当前拼团人数");
		}
		Long version = gp.get(0).getVersion();
		  
		savegrouponBean2.getGrouponCatalogs().forEach(gc -> {
			List<GrouponCatalogs> catalogs = YmtProductsIWapper.selectGrouponCatalogs(gc.getCatalogId(), version.intValue());
			Logger.verifyEquals(1, catalogs.size(), "验证有数据CatalogId:" + gc.getCatalogId());
			Logger.verifyEquals(gc.getGrouponPrice().setScale(2), catalogs.get(0).getGrouponPrice().setScale(2), "验证价格");
		});
		Logger.verifyEquals(savegrouponBean2.getGrouponMemberCount(), gp.get(0).getGrouponMemberCount(), "验证GrouponMemberCount");
		Logger.verifyEquals(savegrouponBean2.getGrouponMaxHour(), gp.get(0).getGrouponMaxHour(), "验证GrouponMaxHour");
		//状态：0- 正常，1- 终止拼团，-1- 删除拼团，2- 异常拼团
		Logger.verifyEquals(0, gp.get(0).getStatus(),"验证拼团状态");
		Thread.sleep(5000);
		String actionType = "CreateGroupon";
		String actionType1 = "ModifyGrouponPrice";
		Logger.debug(actionType+"_"+gp.get(0).getVersion());
		List<Map> businessCredentialInfoMap = YmtProductsIWapper.selectBusinessCredentialInfo(savegrouponBean2.getProductId(),actionType,gp.get(0).getVersion());
		Logger.debug("businessCredentialInfoMap:"+businessCredentialInfoMap);
		if(isModify){
			List<Map> businessCredentialInfoMap1 = YmtProductsIWapper.selectBusinessCredentialInfo(savegrouponBean2.getProductId(),actionType1,gp.get(0).getVersion());
			Logger.verifyEquals(gp.get(0).getGrouponProductId(),businessCredentialInfoMap1.get(0).get("LiveId"),"验证拼团商品自增id");
			Logger.verifyEquals(savegrouponBean2.getSellerId(),businessCredentialInfoMap1.get(0).get("SellerId"),"验证sellerId");
		}else{
			Logger.verifyEquals(gp.get(0).getGrouponProductId(),businessCredentialInfoMap.get(0).get("LiveId"),"验证拼团商品自增id");
			Logger.verifyEquals(savegrouponBean2.getSellerId(),businessCredentialInfoMap.get(0).get("SellerId"),"验证sellerId");
			Logger.verifyEquals(gp.get(0).getGrouponProductId(), savegrouponCall.getJsonObject().get("data").getAsInt(), "验证id");
		}
		
		return gp.get(0).getGrouponProductId();
		}else {
			return null;
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SaveGroupon_001() {
		Logger.start(true,"创建拼团成功,单规格");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			addAgentProductBean.getCatalogList().remove(1);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogList.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(BigDecimal.valueOf(100));
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(mchId);
			savegrouponBean.setGrouponMaxHour(3);
			savegrouponBean.setGrouponMemberCount(4);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(0,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();		
			Logger.verifyEquals("200", savegrouponCall.getString("code"), "验证code");
//			Integer getGrouponProductId = verifyDB(savegrouponBean, false);
			
//			verifyGroupMq(getGrouponProductId,pid,"create_groupon_god");
//			verifyMongoCurMq(getGrouponProductId,pid,"CreateGroupon");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_002() {
		Logger.start(true,"编辑拼团成功,单规格");
		try {
			//创建一个渠道商，单规格渠道商品，   获取到规格id
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			addAgentProductBean.getCatalogList().remove(1);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			//创建拼团
			savegrouponBean=Shop2cnGrouponCallService.initSaveGrouponReq(mchId, pid, catalogList.get(0), 100d);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(2,"yyyy-MM-dd HH:mm:ss"));
			Integer tuanid = Shop2cnGrouponCallService.SaveGrouponCall(savegrouponBean);
			Logger.comment("创建拼团："+tuanid);
			savegrouponBean.setGrouponProductId(tuanid);
//			savegrouponBean.setGrouponMaxHour(3);
//			savegrouponBean.setGrouponMemberCount(4);
			savegrouponBean.getGrouponCatalogs().get(0).setGrouponPrice(BigDecimal.valueOf(110d));
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("200", savegrouponCall.getString("code"), "验证code");
//			Integer getGrouponProductId = verifyDB(savegrouponBean, true);
//			verifyMongoCurMq(getGrouponProductId,pid,"ModifyGrouponPrice");
//			verifyGroupMq(getGrouponProductId,pid,"edit_groupon_god");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_003() {
		Logger.start(true,"不输入productId失败");
		try {

			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			addAgentProductBean.getCatalogList().remove(1);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogList.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(BigDecimal.valueOf(100));
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
//			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(mchId);
			savegrouponBean.setGrouponMaxHour(3);
			savegrouponBean.setGrouponMemberCount(4);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(0,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();		
			Logger.verifyEquals("400", savegrouponCall.getString("code"), "验证code");
			Logger.verifyEquals("商品Id不能为空", savegrouponCall.getString("message"), "商品Id不能为空");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_004() {
		Logger.start(true,"不输入sellerId失败");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			addAgentProductBean.getCatalogList().remove(1);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogList.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(BigDecimal.valueOf(100));
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setProductId(pid);
//			savegrouponBean.setSellerId(mchId);
			savegrouponBean.setGrouponMaxHour(3);
			savegrouponBean.setGrouponMemberCount(4);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(0,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();		
			Logger.verifyEquals("400", savegrouponCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_005() {
		Logger.start(true,"不输入grouponCatalogs失败");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			addAgentProductBean.getCatalogList().remove(1);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogList.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(BigDecimal.valueOf(100));
				grouponCatalogs.add(e);
			});
//			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(mchId);
			savegrouponBean.setGrouponMaxHour(3);
			savegrouponBean.setGrouponMemberCount(4);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(0,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();		
			Logger.verifyEquals("400", savegrouponCall.getString("code"), "验证code");
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_006() {
		Logger.start(true,"不输入grouponMemberCount失败");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			addAgentProductBean.getCatalogList().remove(1);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogList.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(BigDecimal.valueOf(100));
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(mchId);
			savegrouponBean.setGrouponMaxHour(3);
//			savegrouponBean.setGrouponMemberCount(4);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(0,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();		
			Logger.verifyEquals("400", savegrouponCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_007() {
		Logger.start(true,"grouponMemberCount小于2失败");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			addAgentProductBean.getCatalogList().remove(1);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogList.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(BigDecimal.valueOf(100));
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(mchId);
			savegrouponBean.setGrouponMaxHour(3);
			savegrouponBean.setGrouponMemberCount(1);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(0,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();		
			Logger.verifyEquals("400", savegrouponCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_008() {
		Logger.start(true,"不输入grouponMaxHour失败");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			addAgentProductBean.getCatalogList().remove(1);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogList.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(BigDecimal.valueOf(100));
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(mchId);
//			savegrouponBean.setGrouponMaxHour(3);
			savegrouponBean.setGrouponMemberCount(4);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(0,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();		
			Logger.verifyEquals("400", savegrouponCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_009() {
		Logger.start(true,"grouponMaxHour小于1失败");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			addAgentProductBean.getCatalogList().remove(1);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogList.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(BigDecimal.valueOf(100));
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(mchId);
			savegrouponBean.setGrouponMaxHour(0);
			savegrouponBean.setGrouponMemberCount(4);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(0,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();		
			Logger.verifyEquals("400", savegrouponCall.getString("code"), "验证code");
		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_010() {
		Logger.start(true,"不输入beginTime失败");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			addAgentProductBean.getCatalogList().remove(1);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogList.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(BigDecimal.valueOf(100));
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(mchId);
			savegrouponBean.setGrouponMaxHour(2);
			savegrouponBean.setGrouponMemberCount(4);
//			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(0,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();		
			Logger.verifyEquals("400", savegrouponCall.getString("code"), "验证code");
		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_011() {
		Logger.start(true,"不输入endTime失败");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			addAgentProductBean.getCatalogList().remove(1);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogList.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(BigDecimal.valueOf(100));
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(mchId);
			savegrouponBean.setGrouponMaxHour(2);
			savegrouponBean.setGrouponMemberCount(4);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(0,"yyyy-MM-dd HH:mm:ss"));
//			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();		
			Logger.verifyEquals("400", savegrouponCall.getString("code"), "验证code");
		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SaveGroupon_012() {
		Logger.start(true,"创建拼团成功,多规格");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
//			addAgentProductBean.getCatalogList().remove(1);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			
			List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
			catalogList.forEach(catalogId -> {
				GrouponCatalogDto e = new GrouponCatalogDto();
				e.setCatalogId(catalogId);
				e.setGrouponPrice(BigDecimal.valueOf(100));
				grouponCatalogs.add(e);
			});
			savegrouponBean.setGrouponCatalogs(grouponCatalogs);
			savegrouponBean.setProductId(pid);
			savegrouponBean.setSellerId(mchId);
			savegrouponBean.setGrouponMaxHour(3);
			savegrouponBean.setGrouponMemberCount(4);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(0,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();		
			Logger.verifyEquals("200", savegrouponCall.getString("code"), "验证code");
//			Integer getGrouponProductId = verifyDB(savegrouponBean, false);
//			
//			verifyGroupMq(getGrouponProductId,pid,"create_groupon_god");
//			verifyMongoCurMq(getGrouponProductId,pid,"CreateGroupon");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_013() {
		Logger.start(true,"编辑拼团成功,多规格");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			
			savegrouponBean=Shop2cnGrouponCallService.initSaveGrouponReq(mchId, pid, catalogList, 100d);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(2,"yyyy-MM-dd HH:mm:ss"));
			Integer tuanid = Shop2cnGrouponCallService.SaveGrouponCall(savegrouponBean);
			Logger.comment("创建拼团成功、团Id："+tuanid);
			
			
			savegrouponBean.setGrouponProductId(tuanid);
			savegrouponBean.setGrouponMaxHour(3);
			savegrouponBean.setGrouponMemberCount(4);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			
			Logger.verifyEquals("200", savegrouponCall.getString("code"), "验证code");
//			Integer getGrouponProductId = verifyDB(savegrouponBean, false);
//			
//			verifyGroupMq(getGrouponProductId,pid,"create_groupon_god");
//			verifyMongoCurMq(getGrouponProductId,pid,"CreateGroupon");
//			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_014() {
		Logger.start(true,"创建商品拼团价大于原价，拼团失败");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			
			savegrouponBean=Shop2cnGrouponCallService.initSaveGrouponReq(mchId, pid, catalogList, 5000d);
			
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("201", savegrouponCall.getString("code"), "拼团价必须大于0");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_015() {
		Logger.start(true,"创建商品拼团价小于0，拼团失败");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			
			savegrouponBean=Shop2cnGrouponCallService.initSaveGrouponReq(mchId, pid, catalogList, 0d);
			
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("400", savegrouponCall.getString("code"), "拼团价必须大于0");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_016() {
		Logger.start(true,"创建代理商品拼团价小于拿货价，拼团失败");
		try {
			
			//vip渠道
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,vipRootUserName,true);
			
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			//vip代理1
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(vipAgentUserId1,vipAgentUserName1,productId,vipRootUserId,true);
			String pid = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);
			
			
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(vipAgentUserId1,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			
			
			double price1 = 10000d;
			List<DetailsCatalogDto> catalog = selectProductDetails.getCatalogList();
			for (int i = 0; i < catalog.size(); i++) {
				double agentPrice = catalog.get(i).getAgentPrice();
				price1=agentPrice<price1?agentPrice:price1;
				
			}
			savegrouponBean=Shop2cnGrouponCallService.initSaveGrouponReq(vipAgentUserId1, pid, catalogList, price1-1);
			
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("201", savegrouponCall.getString("code"), "拼团价小鱼成本价");
			
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_017() {
		Logger.start(true,"创建渠道商品拼团价小于标价大于0，拼团成功");
		try {

			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			
			savegrouponBean=Shop2cnGrouponCallService.initSaveGrouponReq(mchId, pid, catalogList, 0.01d);
			
			Integer tuanid = Shop2cnGrouponCallService.SaveGrouponCall(savegrouponBean);
			savegrouponBean.setGrouponProductId(tuanid);
//			Integer getGrouponProductId = verifyDB(savegrouponBean, false);
//			
//			verifyGroupMq(getGrouponProductId,pid,"create_groupon_god");
			verifyMongoCurMq(tuanid,pid,"CreateGroupon");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_018() {
		Logger.start(true,"创建拼团，商品已经参与拼团活动且时间冲突，拼团失败");
		try {

			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			
			savegrouponBean=Shop2cnGrouponCallService.initSaveGrouponReq(mchId, pid, catalogList, 0.01d);
			Integer tuanid = Shop2cnGrouponCallService.SaveGrouponCall(savegrouponBean);
			
//			savegrouponBean=Shop2cnGrouponCallService.initSaveGrouponReq(mchId, pid, catalogList, 0.01d);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			
			savegrouponBean.setGrouponProductId(tuanid);
//			Integer getGrouponProductId = verifyDB(savegrouponBean, false);
//			
//			verifyGroupMq(getGrouponProductId,pid,"create_groupon_god");
			verifyMongoCurMq(tuanid,pid,"CreateGroupon");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_019() {
		Logger.start(true,"创建拼团，商品已经参与拼团活动但时间不冲突，拼团成功");
		try {
			//创建一个渠道商，单规格渠道商品，   获取到规格id
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			addAgentProductBean.getCatalogList().remove(1);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			//创建拼团
			savegrouponBean=Shop2cnGrouponCallService.initSaveGrouponReq(mchId, pid, catalogList.get(0), 100d);
			Integer tuanid = Shop2cnGrouponCallService.SaveGrouponCall(savegrouponBean);
			Logger.comment("创建拼团："+tuanid);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(3,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(4,"yyyy-MM-dd HH:mm:ss"));
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();	
			
			Logger.verifyEquals(200, savegrouponCall.getStatusCode(), "时间不冲突的拼团创建成功");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_020() {
		Logger.start(true,"创建拼团，商品已经参与其他优惠活动-满减，拼团失败");
		try {
			//创建一个渠道商，单规格渠道商品，   获取到规格id
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			addAgentProductBean.getCatalogList().remove(1);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			
			CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(mchId, 3);
			createpromotionBean.setCurrency("USD");
			Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
			
			
			//创建拼团
			savegrouponBean=Shop2cnGrouponCallService.initSaveGrouponReq(mchId, pid, catalogList.get(0), 100d);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();	
			Logger.verifyEquals("400", savegrouponCall.getString("code"), "时间不冲突的拼团创建成功");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_021() {
		Logger.start(true,"创建拼团，商品已经参与其他优惠活动-限时折扣，拼团失败");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
		 	String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			//创建限时抢购活动
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,productId);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			AddactivityBean initProductaddactivity = AgentProductCallService.initProductaddactivity(mchId, productId, catalogList);
			int activityId = AgentProductCallService.agentProductaddactivity(initProductaddactivity);
			Thread.sleep(4000);
			
			//创建拼团
			savegrouponBean=Shop2cnGrouponCallService.initSaveGrouponReq(mchId, productId, catalogList.get(0), 100d);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();	
			Logger.verifyEquals("400", savegrouponCall.getString("code"), "有限时折，拼团创建失败");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_024() {
		Logger.start(true,"编辑拼团sellerid和grouponProductId不匹配(不是自己商品)，失败");
		try {

			//创建一个渠道商，单规格渠道商品，   获取到规格id
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			Integer mchId1 = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			addAgentProductBean.getCatalogList().remove(1);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			//创建拼团
			savegrouponBean=Shop2cnGrouponCallService.initSaveGrouponReq(mchId, pid, catalogList.get(0), 100d);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(2,"yyyy-MM-dd HH:mm:ss"));
			Integer tuanid = Shop2cnGrouponCallService.SaveGrouponCall(savegrouponBean);
			Logger.comment("创建拼团："+tuanid);
			
			
			savegrouponBean.setGrouponProductId(tuanid);
//			savegrouponBean.setGrouponMaxHour(3);
//			savegrouponBean.setGrouponMemberCount(4);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(3,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(4,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.getGrouponCatalogs().get(0).setGrouponPrice(BigDecimal.valueOf(110d));
			savegrouponBean.setSellerId(mchId1);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();	
			Logger.verifyEquals("200", savegrouponCall.getString("code"), "验证code");
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_025() {
		Logger.start(true,"编辑商品拼团价大于原价，拼团失败");
		try {
			//创建一个渠道商，单规格渠道商品，   获取到规格id
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			addAgentProductBean.getCatalogList().remove(1);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			//创建拼团
			savegrouponBean=Shop2cnGrouponCallService.initSaveGrouponReq(mchId, pid, catalogList.get(0), 100d);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(2,"yyyy-MM-dd HH:mm:ss"));
			Integer tuanid = Shop2cnGrouponCallService.SaveGrouponCall(savegrouponBean);
			Logger.comment("创建拼团："+tuanid);
			
			
			savegrouponBean.setGrouponProductId(tuanid);
//			savegrouponBean.setGrouponMaxHour(3);
//			savegrouponBean.setGrouponMemberCount(4);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(3,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(4,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.getGrouponCatalogs().get(0).setGrouponPrice(BigDecimal.valueOf(99999d));
			savegrouponBean.setSellerId(mchId);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			
			
			Logger.verifyEquals("201", savegrouponCall.getString("code"), "拼团价必须大于原价");
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_026() {
		Logger.start(true,"编辑商品拼团价小于0，拼团失败");
		try {
			//创建一个渠道商，单规格渠道商品，   获取到规格id
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			addAgentProductBean.getCatalogList().remove(1);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			//创建拼团
			savegrouponBean=Shop2cnGrouponCallService.initSaveGrouponReq(mchId, pid, catalogList.get(0), 100d);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(2,"yyyy-MM-dd HH:mm:ss"));
			Integer tuanid = Shop2cnGrouponCallService.SaveGrouponCall(savegrouponBean);
			Logger.comment("创建拼团："+tuanid);
			
			savegrouponBean.setGrouponProductId(tuanid);
//			savegrouponBean.setGrouponMaxHour(3);
//			savegrouponBean.setGrouponMemberCount(4);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(3,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(4,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.getGrouponCatalogs().get(0).setGrouponPrice(BigDecimal.valueOf(0d));
			savegrouponBean.setSellerId(mchId);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			
			
			Logger.verifyEquals("400", savegrouponCall.getString("code"), "拼团价必须大于0");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_027() {
		Logger.start(true,"编辑代理商品拼团价小于拿货价，拼团失败");
		try {
			//vip渠道
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,vipRootUserName,true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			//vip代理1
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(vipAgentUserId1,vipAgentUserName1,productId,vipRootUserId,true);
			String pid = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(vipAgentUserId1,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			double price1 = 10000d;
			List<DetailsCatalogDto> catalog = selectProductDetails.getCatalogList();
			for (int i = 0; i < catalog.size(); i++) {
				double agentPrice = catalog.get(i).getAgentPrice();
				price1=agentPrice<price1?agentPrice:price1;
			}
			
			//创建拼团
			savegrouponBean=Shop2cnGrouponCallService.initSaveGrouponReq(vipAgentUserId1, pid, catalogList.get(0), 300d);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(2,"yyyy-MM-dd HH:mm:ss"));
			Integer tuanid = Shop2cnGrouponCallService.SaveGrouponCall(savegrouponBean);
			Logger.comment("创建拼团："+tuanid);
			final double price = price1;
			savegrouponBean.getGrouponCatalogs().forEach(b->{
				b.setGrouponPrice(new BigDecimal(price-1d));
			});
			savegrouponBean.setGrouponProductId(tuanid);
//			savegrouponBean.setGrouponMaxHour(3);
//			savegrouponBean.setGrouponMemberCount(4);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(3,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(4,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.getGrouponCatalogs().get(0).setGrouponPrice(BigDecimal.valueOf(50d));
			savegrouponBean.setSellerId(vipAgentUserId1);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			Logger.verifyEquals("201", savegrouponCall.getString("code"), "拼团价必须大于0");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_028() {
		Logger.start(true,"编辑渠道商品拼团价小于标价大于0，拼团成功");
		try {
			
			//创建一个渠道商，单规格渠道商品，   获取到规格id
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			addAgentProductBean.getCatalogList().remove(1);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			//创建拼团
			savegrouponBean=Shop2cnGrouponCallService.initSaveGrouponReq(mchId, pid, catalogList.get(0), 100d);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(2,"yyyy-MM-dd HH:mm:ss"));
			Integer tuanid = Shop2cnGrouponCallService.SaveGrouponCall(savegrouponBean);
			Logger.comment("创建拼团："+tuanid);
			
			savegrouponBean.setGrouponProductId(tuanid);
//			savegrouponBean.setGrouponMaxHour(3);
//			savegrouponBean.setGrouponMemberCount(4);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(3,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(4,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.getGrouponCatalogs().get(0).setGrouponPrice(BigDecimal.valueOf(50d));
			savegrouponBean.setSellerId(mchId);
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			
			
			Logger.verifyEquals("200", savegrouponCall.getString("code"), "拼团价必须大于0");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_029() {
		Logger.start(true,"编辑拼团/已经开始--只能修改结束时间");
		try {

			//创建一个渠道商，单规格渠道商品，   获取到规格id
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			addAgentProductBean.getCatalogList().remove(1);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			//创建拼团
			savegrouponBean=Shop2cnGrouponCallService.initSaveGrouponReq(mchId, pid, catalogList.get(0), 100d);
			Integer tuanid = Shop2cnGrouponCallService.SaveGrouponCall(savegrouponBean);
			Logger.comment("创建拼团："+tuanid);
			
			savegrouponBean.setGrouponProductId(tuanid);
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(4,"yyyy-MM-dd HH:mm:ss"));
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			
			
			Logger.verifyEquals("200", savegrouponCall.getString("code"), "拼团价必须大于0");
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	//H93H28VPA8
	
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SaveGroupon_030() {
		Logger.start(true,"创建拼团，与一个已经结束的拼团活动时间冲突，拼团成功");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId, "AutoTest",
					false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList = new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId, pid);
			selectProductDetails.getCatalogList().forEach(a -> {
				catalogList.add(a.getCatalogId());
			});
			savegrouponBean = Shop2cnGrouponCallService.initSaveGrouponReq(mchId, pid,
					catalogList.get(0), 100d);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(-2, "yyyy-MM-dd HH:mm:ss"));
			String dateBeforeOrNextSecond = YMTDateUtil
					.getDateBeforeOrNextSecond(YMTDateUtil.getSysTime("yyyy-MM-dd HH:mm:ss"), 10);
			savegrouponBean.setEndTime(dateBeforeOrNextSecond);
			Integer tuanid = Shop2cnGrouponCallService.SaveGrouponCall(savegrouponBean);
			while(true){
				JsonObject grouponProductInfo = Shop2cnGrouponCallService.GrouponProductInfo(mchId, tuanid);
				Thread.sleep(2000);
				if(grouponProductInfo.get("status").getAsInt()==3){
					break;
				}
			}
			Thread.sleep(5000);
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(2, "yyyy-MM-dd HH:mm:ss"));
			savegrouponCall.setData(savegrouponBean);
			savegrouponCall.callService();
			tuanid = savegrouponCall.getJsonObject().get("data").getAsInt();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
}